package com.xin.di.uav.applet.controller;

import com.xin.di.uav.applet.request.DeliveryPointsAddParam;
import com.xin.di.uav.applet.request.DeliveryPointsEditParam;
import com.xin.di.uav.applet.resp.DeliveryPointsResp;
import com.xin.di.uav.applet.service.DeliveryPointsService;
import com.xin.di.uav.common.request.common.IdRequest;
import com.xin.di.uav.common.utils.Rs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/home/delivery-points/")
public class DeliveryPointsController {

    @Autowired
    private DeliveryPointsService deliveryPointsService;

    @PostMapping("add")
    public Rs<Boolean> add(@RequestBody @Valid DeliveryPointsAddParam deliveryPointsAddParam) {
        return Rs.success(deliveryPointsService.add(deliveryPointsAddParam));
    }

    @PutMapping("update")
    public Rs<Boolean> edit(@RequestBody @Valid DeliveryPointsEditParam deliveryPointsEditParam) {
        return Rs.success(deliveryPointsService.edit(deliveryPointsEditParam));
    }

    @GetMapping("list")
    public Rs<DeliveryPointsResp> list(@RequestParam int page, @RequestParam int pageSize
            , @RequestParam(required = false) String name) {
        return Rs.success(deliveryPointsService.list(page, pageSize, name));
    }

    @PutMapping("update-status")
    public Rs<Boolean> updateStatus(@RequestBody @Valid IdRequest idRequest) {
        return Rs.success(deliveryPointsService.updateStatus(idRequest));
    }
}
